#include "Ground.h"

Ground::Ground(b2World* world, b2Vec2 groundPosition, float32 groundFriction)
{
	m_world = world;
	m_groundFriction = groundFriction;
	m_groundPosition = groundPosition;

	b2BodyDef myBodyDef;
	myBodyDef.type = b2_staticBody;
	myBodyDef.position = m_groundPosition;

	b2EdgeShape groundShape;
	groundShape.Set(b2Vec2(-1.5f, 0.0f), b2Vec2(1.5f, 0.0f));
	b2FixtureDef myFixtureDef;
	myFixtureDef.shape = &groundShape;
	myFixtureDef.density = 0.0f;
	myFixtureDef.friction = m_groundFriction;
	m_groundBody = m_world->CreateBody(&myBodyDef);
	m_groundBody->CreateFixture(&myFixtureDef);

	groundShape.Set(b2Vec2(-1.5f, 0.0f), b2Vec2(-1.5f, 1.2f));
	myFixtureDef.shape = &groundShape;
	myFixtureDef.density = 0.0;
	myFixtureDef.friction = m_groundFriction;
	m_groundBody->CreateFixture(&myFixtureDef);

	groundShape.Set(b2Vec2(1.5f, 0.0f), b2Vec2(1.5f, 1.2f));
	myFixtureDef.shape = &groundShape;
	myFixtureDef.density = 0.0;
	myFixtureDef.friction = m_groundFriction;
	m_groundBody->CreateFixture(&myFixtureDef);
}

Ground::~Ground()
{
	if(m_groundBody != NULL)
	{
		m_world ->DestroyBody(m_groundBody);
		m_groundBody = NULL;
	}
}

b2Vec2 Ground::GetGroundPosition()
{
	return m_groundBody->GetPosition();
}

b2Body* Ground::GetGroundBody()
{
	return m_groundBody;
}

float32 Ground::GetGroundFriction()
{
	return m_groundFriction;
}

void Ground::SetGroundFriction(const float32& val)
{
	m_groundFriction = val;
}